using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Game : MonoBehaviour
{

    public enum Game_STATUS
    {
        Ready,
        InGame,
        GameOver
    }

    public  Game_STATUS Status
    {
        get { return status; }
        set { this.status = value;
            this.UpdateUI();
        }
        
    }

    private Game_STATUS status;

    public GameObject panelReady;
    public GameObject panelInGame;
    public GameObject panelGameOver;

    public Player player;

    public Pipeline pipelineManager;

    public int score;
    
    public Text uiScore;
    public Text uiScore2;
    public int Score
    {
        get { return score; }
        set
        {
            this.score = value;
            this.uiScore.text = this.score.ToString();
            this.uiScore2.text = this.score.ToString();
        }
    }

    // Start is called before the first frame update
    void Start()
    {
        this.panelReady.SetActive(true);
        Status = Game_STATUS.Ready;
        this.player.OnDeath += Player_OnDeath;
        this.player.OnScore = OnPlayerScore;
    }

    void OnPlayerScore(int score)
    {
        this.Score += score;
    }

    private void Player_OnDeath()
    {
        this.Status = Game_STATUS.GameOver;
        this.pipelineManager.Stop();
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void StartGame()
    {
        this.Status = Game_STATUS.InGame;
       
        pipelineManager.StartRun();
        player.Fly();
    }

    public void UpdateUI()
    {
        this.panelReady.SetActive(this.Status == Game_STATUS.Ready);
        this.panelInGame.SetActive(this.Status == Game_STATUS.InGame);
        this.panelGameOver.SetActive(this.Status == Game_STATUS.GameOver);
    }

    public void Restart()
    {
        this.Status = Game_STATUS.Ready;
        this.pipelineManager.Init();
        this.player.Init();
        score = 0;
        this.uiScore.text = this.score.ToString();
        this.uiScore2.text = this.score.ToString();
    }
}
